package com.preskool.service.impl;

import com.preskool.dto.SubjectVo;
import com.preskool.mapper.SubjectsMapper;
import com.preskool.po.Subjects;
import com.preskool.po.SubjectsExample;
import com.preskool.service.SubjectsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author kennyzzz
 * @Data 2021/1/11 4:21
 */
@Service
public class SubjectsServiceImpl implements SubjectsService {

    @Autowired(required = false)
    private SubjectsMapper subjectsMapper;
    @Override
    public List<Subjects> findAllSubject() {
        return subjectsMapper.findAll();
    }

    @Override
    public Subjects findSubjectByName(String subjectName) {
        return subjectsMapper.selectBySubjectName(subjectName);
    }

    @Override
    public List<SubjectVo> findSubjectsByPage(Integer currentPage, Integer pageSize, String sortName) {
        SubjectsExample example = new SubjectsExample();
        example.setOffset((currentPage-1)*pageSize);
        example.setLimit(pageSize);
        example.setOrderByClause(sortName);

        return subjectsMapper.selectSubjectsByPage(example);
    }

    @Override
    public int addSubject(Subjects subjects) {
        return subjectsMapper.insertSelective(subjects);
    }

    @Override
    public int deleteSubjectBySubid(Integer subid) {
        return subjectsMapper.deleteByPrimaryKey(subid);
    }

    @Override
    public int updateSubject(Subjects subjects) {
        return subjectsMapper.updateByPrimaryKey(subjects);
    }

}
